package top.yuki.event;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import top.yuki.LevelWorld;
import top.yuki.data.DataManager;
import top.yuki.data.DayDataManager;
import top.yuki.data.TempDataManage;
import top.yuki.data.WorldManage;

public class onCreatureSpawn implements Listener {
    public DataManager dataManage;
    private TempDataManage tempDataManage;
    private DayDataManager dayDataManager;
    private WorldManage worldManage;
    private ConfigurationSection config;
    public onCreatureSpawn (LevelWorld lw){
        this.dataManage = lw.dataManage;
        this.tempDataManage = lw.tempDataManage;
        this.dayDataManager = lw.dayDataManager;
        this.worldManage = lw.worldManage;
        this.config = lw.getConfig();
    }

    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent e){
        CreatureSpawnEvent.SpawnReason spawnReason = e.getSpawnReason();
        LivingEntity entity = e.getEntity();
        int worldLevel = worldManage.getWorldLevel(entity.getLocation().getWorld().getName());
        double worldMobHealthMagnification = Double.valueOf(String.valueOf(config.get("worldMobHealthMagnification." + worldLevel))) ;
        double maxHealth = entity.getMaxHealth();
        entity.setMaxHealth((int)maxHealth*worldMobHealthMagnification);
        entity.setHealth((int)maxHealth*worldMobHealthMagnification);


    }

    public void setMob(EntityDeathEvent event, int worldLevel){
        
        double worldMobHealthMagnification = Double.valueOf(String.valueOf(config.get("worldMobHealthMagnification." + worldLevel))) ;
        LivingEntity entity = event.getEntity();
        double maxHealth = entity.getMaxHealth();
        entity.setMaxHealth((int)maxHealth*worldMobHealthMagnification);
        entity.setHealth((int)maxHealth*worldMobHealthMagnification);
    }


}
